{include file="public/header" /}
<style type="text/css">
    #des, #des input {
        width: 40px;
        text-align: center;
    }

    #id {
        width: 78px;
    }

    .bs-checkbox {
        width: 36px;
        height: 40px
    }

    .fixed-table-toolbar .columns, .fixed-table-toolbar .search {
        margin-left: 0px;
        margin-top: 0px
    }

    #title span {
        float: right;
    }

    .btn-active {
        background: #1ab394;
        color: #fff
    }
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        {include file="public/tophead"}
        {include file="public/top" /}
        <div class="ibox-content">
            <div class="row row-lg">
                <div class="col-sm-12">
                    <div class="fixed-table-toolbar">
                        <a class="btn btn-default btn-outline {if input('get.field/s') eq ''} btn-active{/if}" href="{:url('content/index')}">所有内容</a>
                        {volist name="types" id="v" }
                        <a class="btn btn-default btn-outline {if input('get.field/s') eq 'type' && input('get.value/s') eq $key} btn-active{/if}" href="{:url('content/index', ['field'=>'type','value' => $key])}">{$v}</a>
                        {/volist}
                    </div>
                </div>
                <div style="display:block;clear: both;"></div>
                <div class="fixed-table-toolbar">
                    <form method="get" action="">
                        <div class="pull-left search">
                            <div class="columns columns-right btn-group pull-left">
                                <select class="form-control" name="type">
                                    <option value="-1">所有分类</option>
                                    {foreach $category as $id => $name}
                                    <option value="{$id}" {if input('get.type/d') eq $id}selected="selected"{/if}>{$name}</option>
                                    {/foreach}
                                </select>
                            </div>
                            <div class="pull-right search">
                                <button style="border-radius:0px; border:1px solid #e5e6e7; border-left:0px"
                                        class="btn btn-default btn-outline" type="submit">搜索
                                </button>
                            </div>
                            <div class="pull-right search">
                                <input class="form-control input-outline" type="text" name="text" placeholder="输入标题搜索" value="{:input('get.text', '')}" />
                            </div>
                        </div>
                    </form>
                </div>
                <div class="example">
                    <form class="form-horizontal" method="post">
                        <table data-toggle="table">
                            <thead>
                                <tr>
                                    <th class="bs-checkbox"><input type="checkbox" id="changeAll" /></th>
                                    <th data-align="center">ID</th>
                                    <th data-align="center">分类</th>
                                    <th data-align="center">发布用户</th>
                                    <th data-align="center">内容</th>
                                    <th data-align="center">活动时间</th>
                                    <th data-align="center">地点</th>
                                    <th data-align="center">类型</th>
                                    <th data-align="center">报名人数</th>
                                    <th data-align="center">发布时间</th>
                                    <th data-align="center">状态</th>
                                    <th data-align="center">管理</th>
                                </tr>
                            </thead>
                            <tbody>
                            {volist name="data" id="vo"}
                            <tr id="id{$vo.id}">
                                <td class="bs-checkbox">
                                    <input type="checkbox" name="opt_item[]" value="{$vo.id}">
                                </td>
                                <td>{$vo.id}</td>
                                <td>{$vo.category_name}</td>
                                <td>{$vo.nickname}</td>
                                <td>{$vo.content}</td>
                                <td>
                                    {if $vo['date_type'] eq -1}
                                        {$vo.begin_date|date='Y-m-d H:i:s'} - {$vo.end_date|date='Y-m-d H:i:s'}
                                    {else}
                                        {$vo.begin_date|date='Y-m-d'} - {$choose_list[$vo['date_type']]['name']}
                                    {/if}
                                </td>
                                <td>{$vo.location}</td>
                                <td>{$vo.type}</td>
                                <td>{$vo.apply_num}</td>
                                <td>{$vo.create_time|date="Y-m-d"}</td>
                                <td>
                                    <span class="btn btn-xs {if $vo.audit_type eq 1}btn-default{else}btn-primary{/if}" {if $vo.audit_type eq 3}style="background-color: #414141;border-color:#414141"{/if}>
                                        {switch $vo.audit_type}
                                        {case 1}待审核{/case}
                                        {case 2}已审核{/case}
                                        {default /}被拒绝
                                        {/switch}
                                    </span>
                                </td>
                                <td>
                                    <div class="btn-group">
                                        <div data-toggle="dropdown" class="btn btn-primary btn-xs dropdown-toggle">
                                            操作 <span class="caret"></span>
                                        </div>
                                        <ul class="dropdown-menu">
                                            <li><a href="{:url('content/comment', ['content_id' => $vo['id'],'back'=>-1])}">查看评论</a></li>
                                            <li><a onclick="add('{:url('content/add', ['id' => $vo['id']])}')">修改</a></li>
                                            <li class="divider"></li>
                                            {if $vo.audit_type neq 1}
                                            <li><a onclick="audit({$vo.id}, 1)">审核</a></li>
                                            {/if}
                                            {if $vo.audit_type neq 2}
                                            <li><a onclick="audit({$vo.id}, 2)">通过</a></li>
                                            {/if}
                                            {if $vo.audit_type neq 3}
                                            <li><a onclick="audit({$vo.id}, 3)">拒绝</a></li>
                                            {/if}
                                            <li class="divider"></li>
                                            <li><a onclick="del({$vo.id})">删除</a></li>
                                        </ul>
                                    </div>
                                </td>
                            </tr>
                            {/volist}
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>
            <hr>
            <div class="row row-lg">
                <div class="col-sm-12">
                    <div style="float: left; height: 34px; line-height: 34px;">批量：</div>
                    <select class="form-control" id="operateType" style="width: 81px; float:left;">
                        <option value="1">审核</option>
                        <option value="2">通过</option>
                        <option value="3">拒绝</option>
                        <option value="del">删除</option>
                    </select>
                    <div class="btn btn-outline btn-default" id="operateAll" style="margin-left: 0.5%;">
                        批量操作
                    </div>
                    <div class="btn btn-outline btn-default" onclick="window.location.href='{:url('index', ['order' => 'asc'])}'">
                        正序排序
                    </div>
                    <div class="btn btn-outline btn-default" onclick="window.location.href='{:url('index', ['order' => 'desc'])}'">
                        倒序排序
                    </div>
                </div>
            </div>
            <hr>
            <div class="row row-lg">
                <div class="col-sm-12 pages">{$data->render()|raw}</div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
{load href="__STYLE__/admin/plugins/bootstrap/bootstrap-table.min.css"}
{load href="__STYLE__/admin/plugins/bootstrap/bootstrap-table.min.js"}
{load href="__STYLE__/admin/plugins/bootstrap/bootstrap-table-zh-CN.min.js"}
<script type="text/javascript">
$(document).ready(function () {
    $("#changeAll").click(function () {
        if ($("#changeAll").prop('checked')) {
            $("table input[type='checkbox']").prop('checked', true);
        } else  {
            $("table input[type='checkbox']").prop('checked', false);
        }
    });
    $("#operateAll").click(function () {
        var ids = '', type = $("#operateType").val();
        $("table input[type='checkbox']").each(function () {
           if ($(this).prop('checked')){
               if (ids) ids += ',';
               ids += $(this).val();
           }
        });
        if (! ids) {
            layer.msg('请选择内容！', {icon: 5, time: 3000});
            return;
        }
        $.ajax({
            url: "{:url('batchOperate')}",
            type: 'POST',
            dataType: 'JSON',
            data: {ids: ids, type: type},
            success: function (res) {
                if (res.status) {
                    layer.msg(res.msg, {icon:6, time: 2500}, function () {
                        window.location.reload();
                    });
                    return;
                }
                layer.msg(res.msg, {icon: 5, time: 3000});
            },
            error: function () {
                layer.msg('网络错误！', {icon: 2, time: 3000});
            }
        });
    });
});

function add(url){
    layer.open({
        type: 2,
        title: '内容管理',
        shadeClose: false,
        shade: 0.2,
        area: ['80%', '95%'],
        skin:'shangchuantup',
        // shift:-1,
        content: url,
    });
}
function del(id){
    swal_del(id,"{:url('del')}", {title: '该内容'})
}
function audit(id, type) {
    $.ajax({
        url: "{:url('content/audit')}",
        type: 'POST',
        dataType: 'JSON',
        data: {id: id, type: type},
        success: function (res) {
            if (res.status == 1) {
                layer.msg(res.msg, {icon: 1, time: 2500}, function () {
                    window.location.reload();
                });
            } else {
                layer.msg(res.msg, {icon: 5, time: 3000});
            }
        },
        error: function () {
            layer.msg('网络错误', {icon: 2, time: 3000});
        }
    });
}
</script>